package view;

import java.awt.Color;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.text.StyleConstants;

/**
 * A wrapper class to simplify comming view tasks
 * 
 * This class is a helper class that faciliates and simplifies pop ups for error, information and dialog panels as wel as 
 * closing the parent window container and a confirm window option.
 * 
 * @author MUSAB
 *
 * @version $Revision: 1.0 $
 */
public class ViewHelpers {
	
	/**
	 * Some text colors
	 */
	public static Color errorTextColor = new Color(0xB33B3B);
	public static Color warningTextColor = new Color(0xE6CE49);
	public static Color mutedTextColor = new Color(0x969696);
	public static Color successTextColor = new Color(0x80CF4C);
	
	
	/**
	 * Shows an error popup
	 * 
	 * @param message Message in the error popup
	 */
	public static void alertError(String message){
		JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE);
	}

	/**
	 * Shows an information popup
	 * 
	 * @param message The message to be shown
	 * @param title String
	 */
	public static void alertInfo(String message, String title) {
		JOptionPane.showMessageDialog(null, message, title, JOptionPane.INFORMATION_MESSAGE);
	}

	/**
	 * Creates a new popup dialog from a given panel and title
	 * 
	
	
	 * @param panel JPanel
	 * @param title String
	 */
	public static void showDialog(JPanel panel, String title) {
		JOptionPane.showOptionDialog(null, panel, title,
				JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE,
				null, new Object[]{}, null);
	}

	/**
	 * Disposes the parent dialog given a JPanel
	 * 
	
	 * @param jpanel JPanel
	 */
	public static void disposeParentDialog(JPanel jpanel) {
		SwingUtilities.getWindowAncestor(jpanel).dispose();
	}

	/**
	 * Shows a confirm box and returns true or false base on user selection
	 * 
	 * @param message The message to be displayed
	
	 * @return true or false based on ok or cancel */
	public static boolean confirm(String message) {
		
		int response = JOptionPane.showConfirmDialog(null, message, "Input",
                JOptionPane.YES_NO_OPTION);
		if (response== JOptionPane.YES_OPTION){
			return true;
		} else {
			return false;
		}
	}
}
